﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class QuanLyKhieuNaiController : Controller
    {
        //
        // GET: /QuanLyKhieuNai/

        public ActionResult DanhSach()
        {
            DataClassesDataContext dataContext = new DataClassesDataContext();
            var dsDonKhieuNai = from donKhieuNai in dataContext.DonKhieuNais select donKhieuNai;
            List<KhieuNaiModel> dsKhieuNaiModels = new List<KhieuNaiModel>();
            foreach (DonKhieuNai donKhieuNai in dsDonKhieuNai)
            {
                KhieuNaiModel khieuNaiModel = new KhieuNaiModel();
                khieuNaiModel.tieuDe = donKhieuNai.TieuDe;
                khieuNaiModel.noiDung = donKhieuNai.NoiDung;
                khieuNaiModel.ngayGuiKhieuNai = donKhieuNai.Date;
                int khachHangId = donKhieuNai.KhachHang_Id.Value;
                string userName = (from khachHang in dataContext.KhachHangs where khachHang.Id == khachHangId select khachHang).FirstOrDefault().UserName;
                khieuNaiModel.khachHangUserName = userName;
                dsKhieuNaiModels.Add(khieuNaiModel);
            }
            ViewBag.dsKhieuNaiModels = dsKhieuNaiModels;
            ViewBag.MenuClass = Session["MenuClass"];
            return View();
        }

    }
}
